package com.d3works.apps.baml.xml;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

@XmlType
public class LoopNode extends ProcessActionNode {

  @XmlAttribute(name = "target")
  private String target;

  @XmlAttribute(name = "expression")
  private String expression;

  public String getTarget() {
    return target;
  }

  public String getExpression() {
    return expression;
  }

  @Override
  public String toCode(boolean dynamic) {

    StringBuilder codeBuilder = new StringBuilder();

    if (target != null && expression != null) {
      codeBuilder.append("\nfor (" + target + " in " + expression + "){\n");
      codeBuilder.append(super.toCode(dynamic));
      codeBuilder.append("\n}");
    }

    return codeBuilder.toString();
  }
}
